// PZ_BPA.cpp: implementation of the CPZ_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Dat/PZ_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CPZ_BPA::CPZ_BPA()
{
	m_chType = 'P';
	m_chSubType = 'Z';
	memset(m_strZone,' ',2);
	m_strZone[2] = '\0';
	m_dPGenFactor = m_dQGenFactor = m_dPLoadFactor = m_dQLoadFactor = 1.0;

	m_strCardType[0] = 'P';
	m_strCardType[1] = 'Z';

	memset(m_strOwn1,' ',3);
	m_strOwn1[3] = '\0';
	memset(m_strOwn2,' ',3);
	m_strOwn2[3] = '\0';
	memset(m_strOwn3,' ',3);
	m_strOwn3[3] = '\0';
	memset(m_strOwn4,' ',3);
	m_strOwn4[3] = '\0';
	memset(m_strOwn5,' ',3);
	m_strOwn5[3] = '\0';
	memset(m_strOwn6,' ',3);
	m_strOwn6[3] = '\0';
	memset(m_strOwn7,' ',3);
	m_strOwn7[3] = '\0';
	memset(m_strOwn8,' ',3);
	m_strOwn8[3] = '\0';
	memset(m_strOwn9,' ',3);
	m_strOwn9[3] = '\0';
	memset(m_strOwn10,' ',3);
	m_strOwn10[3] = '\0';
	memset(m_strOwn11,' ',3);
	m_strOwn11[3] = '\0';
}

CPZ_BPA::CPZ_BPA(CPZ_BPA &pzBPA):CCard_BPA(pzBPA)
{
	m_chType = pzBPA.m_chType;
	m_chSubType = pzBPA.m_chSubType;
	strcpy(m_strZone,pzBPA.m_strZone);
	m_dPGenFactor = pzBPA.m_dPGenFactor;
	m_dQGenFactor = pzBPA.m_dQGenFactor;
	m_dPLoadFactor = pzBPA.m_dPLoadFactor;
	m_dQLoadFactor = pzBPA.m_dQLoadFactor;
	strcpy(m_strOwn1,pzBPA.m_strOwn1);
	strcpy(m_strOwn2,pzBPA.m_strOwn2);
	strcpy(m_strOwn3,pzBPA.m_strOwn3);
	strcpy(m_strOwn4,pzBPA.m_strOwn4);
	strcpy(m_strOwn5,pzBPA.m_strOwn5);
	strcpy(m_strOwn6,pzBPA.m_strOwn6);
	strcpy(m_strOwn7,pzBPA.m_strOwn7);
	strcpy(m_strOwn8,pzBPA.m_strOwn8);
	strcpy(m_strOwn9,pzBPA.m_strOwn9);
	strcpy(m_strOwn10,pzBPA.m_strOwn10);
	strcpy(m_strOwn11,pzBPA.m_strOwn11);
}

CPZ_BPA::~CPZ_BPA()
{

}		

bool CPZ_BPA::Equals(CListItem *pItem)
{
	CPZ_BPA* pPZ = (CPZ_BPA*)pItem;
	if (!strcmp(m_strZone,pPZ->m_strZone) && !strcmp(m_strOwn1,pPZ->m_strOwn1))
		return true;
	
	return false;
}

bool CPZ_BPA::FillEx(char *buffer)
{
	int i;

	if (EndOfSec(&buffer[0],1))
	{
		printf("Error in (CPZ_BPA: FillEx): no type!\n");
		return false;
	}
	m_chType = buffer[0];

	if (EndOfSec(&buffer[1],1))
	{
		printf("Error in (CPZ_BPA: FillEx): no subtype!\n");
		return false;
	}
	m_chSubType = buffer[1];

	if (EndOfSec(&buffer[2],1))
		return false;

	for (i=0;i<2;i++)
	{
		if(!buffer[3+i])
			break;
		else
			m_strZone[i] = buffer[3+i];
	}
	m_strZone[2] = '\0';
	if(i!=2)
		return true;

	if (EndOfSec(&buffer[5],4))
		return true;
	
	if (!IfAllBlankSpace(&buffer[9],5))
		m_dQLoadFactor = m_dPLoadFactor = StrToDouble(&buffer[9],5);
	if(EndOfSec(&buffer[9],6))
		return true;

	if (!IfAllBlankSpace(&buffer[15],5))
		m_dQLoadFactor = StrToDouble(&buffer[15],5);
	if(EndOfSec(&buffer[15],6))
		return true;

	if (!IfAllBlankSpace(&buffer[21],5))
		m_dQGenFactor = m_dPGenFactor = StrToDouble(&buffer[21],5);
	if(EndOfSec(&buffer[21],6))
		return true;
	
	if (!IfAllBlankSpace(&buffer[27],5))
		m_dQGenFactor = StrToDouble(&buffer[27],5);

	if(EndOfSec(&buffer[27],6))
		return true;

	for (i=0;i<3;i++)
	{
		if(!buffer[34+i])
			break;
		else
			m_strOwn1[i] = buffer[34+i];
	}
	m_strOwn1[3] = '\0';
	if(EndOfSec(&buffer[34],4))
		return true;
	for (i=0;i<3;i++)
	{
		if(!buffer[38+i])
			break;
		else
			m_strOwn2[i] = buffer[38+i];
	}
	m_strOwn2[3] = '\0';
	if(EndOfSec(&buffer[38],4))
		return true;
	for (i=0;i<3;i++)
	{
		if(!buffer[42+i])
			break;
		else
			m_strOwn3[i] = buffer[42+i];
	}
	m_strOwn3[3] = '\0';
	if(EndOfSec(&buffer[42],4))
		return true;

	for (i=0;i<3;i++)
	{
		if(!buffer[46+i])
			break;
		else
			m_strOwn4[i] = buffer[46+i];
	}
	m_strOwn4[3] = '\0';
	if(EndOfSec(&buffer[46],4))
		return true;

	for (i=0;i<3;i++)
	{
		if(!buffer[50+i])
			break;
		else
			m_strOwn5[i] = buffer[50+i];
	}
	m_strOwn5[3] = '\0';
	if(EndOfSec(&buffer[50],4))
		return true;

	for (i=0;i<3;i++)
	{
		if(!buffer[54+i])
			break;
		else
			m_strOwn6[i] = buffer[54+i];
	}
	m_strOwn6[3] = '\0';
	if(EndOfSec(&buffer[54],4))
		return true;

	for (i=0;i<3;i++)
	{
		if(!buffer[58+i])
			break;
		else
			m_strOwn7[i] = buffer[58+i];
	}
	m_strOwn7[3] = '\0';
	if(EndOfSec(&buffer[58],4))
		return true;

	for (i=0;i<3;i++)
	{
		if(!buffer[62+i])
			break;
		else
			m_strOwn8[i] = buffer[62+i];
	}
	m_strOwn8[3] = '\0';
	if(EndOfSec(&buffer[62],4))
		return true;

	for (i=0;i<3;i++)
	{
		if(!buffer[66+i])
			break;
		else
			m_strOwn9[i] = buffer[66+i];
	}
	m_strOwn9[3] = '\0';
	if(EndOfSec(&buffer[66],4))
		return true;

	for (i=0;i<3;i++)
	{
		if(!buffer[70+i])
			break;
		else
			m_strOwn10[i] = buffer[70+i];
	}
	m_strOwn10[3] = '\0';
	if(EndOfSec(&buffer[70],4))
		return true;

	for (i=0;i<3;i++)
	{
		if(!buffer[74+i])
			break;
		else
			m_strOwn11[i] = buffer[74+i];
	}
	m_strOwn11[3] = '\0';
	if(EndOfSec(&buffer[74],4))
		return true;

	
	return true;
}

bool CPZ_BPA::UpdateEx(char *buffer)
{
	buffer[0] = m_chType;
	buffer[1] = m_chSubType;
	buffer[2] = ' ';
	strcpy(&buffer[3],m_strZone);
	strcpy(&buffer[5],"    ");
	DoubleToStr(m_dPLoadFactor,&buffer[9],5);
	buffer[14] = ' ';
	DoubleToStr(m_dQLoadFactor,&buffer[15],5);
	buffer[20] = ' ';
	DoubleToStr(m_dPGenFactor,&buffer[21],5);
	buffer[26] = ' ';
	DoubleToStr(m_dQGenFactor,&buffer[27],5);
	buffer[32] = ' ';
	buffer[33] = ' ';
	strcpy(&buffer[34],m_strOwn1);
	buffer[37] = ' ';
	strcpy(&buffer[38],m_strOwn2);
	buffer[41] = ' ';
	strcpy(&buffer[42],m_strOwn3);
	buffer[45] = ' ';
	strcpy(&buffer[46],m_strOwn4);
	buffer[49] = ' ';
	strcpy(&buffer[50],m_strOwn5);
	buffer[53] = ' ';
	strcpy(&buffer[54],m_strOwn6);
	buffer[57] = ' ';
	strcpy(&buffer[58],m_strOwn7);
	buffer[61] = ' ';
	strcpy(&buffer[62],m_strOwn8);
	buffer[65] = ' ';
	strcpy(&buffer[66],m_strOwn9);
	buffer[69] = ' ';
	strcpy(&buffer[70],m_strOwn10);
	buffer[73] = ' ';
	strcpy(&buffer[74],m_strOwn11);

	return true;
}
